<template>
  <div class="comment-reply-container">
    <!-- 导航 -->
    <van-nav-bar :title="`${currentComment.reply_count}条回复`">
      <van-icon slot="left"
        name="cross"
        @click="$emit('close')" />
    </van-nav-bar>
    <div class="scroll-wrap">
      <!-- 当前回复评论 -->
      <CommentItem :commentContent="currentComment" />
      <!-- /当前回复评论 -->
      <van-cell title="全部回复" />
      <!-- 展示评论的回复列表 -->
      <CommentList :source="currentComment.com_id"
        :list="newReply"
        :type="'c'" />
      <!-- /展示评论的回复列表 -->
      <!-- 发布评论回复 -->
      <div class="post-wrap">
        <van-button class="post-btn"
          size="small"
          round
          @click='isPostShow = true'>写评论</van-button>
      </div>
      <!-- /发布评论回复 -->
    </div>
    <!-- 发布评论的弹层 -->
    <van-popup v-model="isPostShow"
      position="bottom">
      <CommentPub :target="currentComment.com_id"
        :articleId="articleId"
        @pub-comment="onPubReply" />
    </van-popup>
  </div>
</template>

<script>
import CommentItem from './comment-item'
import CommentList from './comment-list'
import CommentPub from './comment-pub'
export default {
  name: 'CommentReply',
  components: {
    CommentItem,
    CommentList,
    CommentPub
  },
  props: {
    currentComment: {
      type: Object,
      required: true
    },
    articleId: {
      type: [Number, String, Object],
      required: true
    }
  },
  data () {
    return {
      isPostShow: false,
      newReply: []
    }
  },
  methods: {
    onPubReply (data) {
      // 1、关闭弹层
      this.isPostShow = false
      // 2、更新数据
      this.newReply.unshift(data)
      // 3、更新回复条数
      this.currentComment.reply_count++
    }
  }
}
</script>

<style scoped lang="less">
.post-wrap {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #fff;
  border-top: 1px solid #d8d8d8;
  .post-btn {
    width: 60%;
  }
}
.scroll-wrap {
  position: fixed;
  top: 92px;
  left: 0;
  right: 0;
  bottom: 88px;
  overflow-y: auto;
}
</style>
